package yifeng.program.utils;

import java.security.InvalidParameterException;
import java.util.Random;

public class Utils {
	
	/**
	 * 获得一个长度为length,数值分布<=toValue, >=fromValue的数组
	 * @param length
	 * @param fromValue
	 * @param toValue
	 * @return
	 */
	public static int[] createIntArray(int length, int fromValue, int toValue){
		if(fromValue >= toValue)
			throw new InvalidParameterException();
		
		int[] intArray = new int[length];
		Random random = new Random();
		for(int i = 0; i < length; i++){
			intArray[i] = random.nextInt(toValue + 1 - fromValue) + fromValue;
		}
		
		return intArray;
	}
	
	

	public static void printArray(int[] a){
		int i = 0;
		for(; i < a.length-1; i++){
			System.out.print(a[i] + "-");
		}
		System.out.println(a[i]);
	}
	
	
	public static void swap(int[] a, int j, int i) {
		int temp;
		temp = a[j];
		a[j] = a[i];
		a[i] = temp;
	}
	
	
}
